/**
 * 鼠标滑轮
 */
import { isFunction } from 'lodash';
import normalizeWheel from 'normalize-wheel';
import { Directive, DirectiveBinding } from 'vue';

import { isFirefox } from '@/utils';

const mousewheel: Directive = {
  mounted(el: HTMLElement, bindin: DirectiveBinding) {
    useEventListener(
      el,
      isFirefox() ? 'DOMMouseScroll' : 'mousewheel',
      event => {
        if (isFunction(bindin.value)) {
          const normalized = normalizeWheel(event);
          bindin.value.apply(this, [event, normalized]);
        }
      }
    );
  }
};

export default mousewheel;
